package com.mj.page;

import com.github.pagehelper.PageHelper;
import com.mj.util.Convernt;

/**
 * pageHelper扩展
 * @author majie
 *
 */
public class PageHelperUtil {
	
	/**
	 * 重写PageHelper的排序方式
	 * 如果orderBy是驼峰，则转换成数据库
	 * @param orderBy
	 * @param descOrAsc
	 */
	public static void orderBy(String orderBy,String descOrAsc){
		if(orderBy != null && orderBy != ""){
			orderBy = Convernt.propertyToColumn(orderBy);
			//为空默认升序
			if(descOrAsc != null && descOrAsc != ""){
				descOrAsc = "asc";
			}
			PageHelper.orderBy(orderBy + " " + descOrAsc);
		}
	}
	/**
	 * 重写PageHelper的分页方式
	 * @param orderBy
	 * @param descOrAsc
	 */
	public static void startPage(Integer pageNo,Integer pageSize){
		//默认第一页,十行
		if(pageNo == null){
			pageNo = 1;
		}
		if(pageSize == null){
			pageSize = 10;
		}
		PageHelper.startPage(pageNo,pageSize);
	}
}
